const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const common = require('../webpack.config.js');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const PROJECT = require('./project.config.js');

module.exports = merge(common, {

    devtool: 'source-map',
    plugins: [

        /**
         * 清理编译的路径文件,目前这里是有问题的，指定的路径不对
         *  outside of the project root
         * https://www.npmjs.com/package/clean-webpack-plugin
         */
        new CleanWebpackPlugin([PROJECT.PATH_DIST], [{ root: PROJECT.PATH_BASE }]),

        new UglifyJSPlugin({
            sourceMap: true
        }),

        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        // 可以使用DLL的方式取代
        new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor', 'manifest'],
            minChunks: Infinity
        })
    ]
});